// src/api/auth.api.js
// import http from './http'
import http from './http'
// http.post()

/********** 用户相关 **********/
// 登录
export const login = async (loginForm) => {
    // const response = await http.post('/auth/login', credentials)
    const response = await http.post('/user/user/login', loginForm)
    return response
}
// 手机验证码登录
export const loginByCode = async (loginForm) => {
    // const response = await http.post('/auth/login', credentials)
    const response = await http.post('/user/user/login/code', loginForm)
    return response
}
// 获取验证码
export const getCode = async (phoneNumber) => {
    // const response = await http.post('/auth/login', credentials)
    const response = await http.get('/user/user/code?phone='+phoneNumber)
    return response
}
// 注册账号
export const register = async (loginForm) => {
    // const response = await http.post('/auth/login', credentials)
    const response = await http.post('/user/user/register', loginForm)
    return response
}
// 登出
export const logout = async () => {
    return await http.get('/user/user/logout')
}

//修改头像
export const updateAvatar = async (userAvatar) => {
    return await http.post('/user/user/avatar?avatarUrl=', {userAvatar})
}

/**
 * 根据id获取用户所有信息
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAllById = async (userId) => {
    return await http.get('/user/user/'+userId)
}

export const getUserBanner = async () => {
    return await http.get('/user/banner')
}


/**
 * 修改用户信息
 */
export const updateById = async (form) => {
    return await http.post('/user/user',form)
}

/**
 * 获取所有用户信息
 * @param page
 * @param pageSize
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAllUser = async (page,pageSize) => {
    return await http.get('/user/user/listAll?page='+page+'&pageSize='+pageSize)
}

/**
 * 获取所有关注用户信息
 * @param page
 * @param pageSize
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAllCaredUser = async (page,pageSize) => {
    return await http.get('/user/user/listAll?page='+page+'&pageSize='+pageSize)
}

// /**
//  * 获取用户的所有信息
//  * @returns {Promise<axios.AxiosResponse<any>>}
//  */
export const getBaseInfo = async () => {
    return await http.get('/user/user/statistics')
}

// 获取用户信息
export const getUserInfo = async (userId) => {
    return await http.get('/user/user/me/'+userId)
}

/**
 * 获取用户的统计信息
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getUserStat = async (userId) => {
    return await http.get(`/user/user/stat?userId=${userId}`)
}

/**
 * 获取所有粉丝用户信息
 * @param page
 * @param pageSize
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAllFansUser = async (page,pageSize) => {
    return await http.get('/user/user/listAllFans?page='+page+'&pageSize='+pageSize)
}

/**
 * 编辑用户个性签名
 * @param page
 * @param pageSize
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const editSignature = async (signatureText) => {
    return await http.put('/user/user/signature', {signatureText})
}


export const refresh = async () => {
    return await http.get('/user/user/refresh')
}






/********** banner图 **********/
export const getCurrentBanner = async () => {
    return await http.get('/user/video/banner');
}



/********** 视频相关 **********/

// 获取分区列表
export const getPartitionList = async () => {
    return await http.get('/user/partition/list')
}
export const getPartitionName = async (pId) => {
    return await http.get('/user/partition/'+pId)
}
export const getVideoListByPartitionId = async (pId,pageParams) => {
    return await http.get(`/user/video/listByPid/${pId}?page=${pageParams.page}&pageSize=${pageParams.pageSize}`)
}

// 获取标签列表
export const getTagList = async (submitForm) => {
    return await http.get('/user/tag/list')
}


export const getVideoList = async (submitForm) => {
    return await http.get('/user/video/list')
}

export const getRecommendList = async (params) => {
    if(params.userId){
        return await http.get(`/user/recommend/for-you?page=${params.page}&pageSize=${params.pageSize}&userId=${params.userId}`)
    }
    return await http.get(`/user/recommend/for-you?page=${params.page}&pageSize=${params.pageSize}`)
}


export const getVideoDetail = async (id,userId) => {
    if(userId){
        return await http.get(`/user/video/detail?id=${id}&userId=${userId}`)
    }
    return await http.get(`/user/video/detail?id=${id}`)
}

export const searchVideo = async (params) => {
    return await http.get(`/user/video/search?keyword=${params.keyword}&page=${params.page}&pageSize=${params.pageSize}&userId=${params.userId}`)
}

/**
 * 获取播放队列
 */
export const getPlayQueue = async (videoId) => {
    return await http.get('/user/recommend/play-next/'+videoId)
}


/**
 *
 * @param videoId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getSubmitVideo = async (userId,pageForm) => {
    return await http.get(`/user/video/list/${userId}?page=${pageForm.page}&pageSize=${pageForm.pageSize}`)
}










/********** 历史记录 **********/

export const updateProgress = async (progressForm) => {
    return await http.put('/user/history/progress', progressForm);
}

export const getProgress = async (userId, videoId) => {
    return await http.get(`/user/history/progress/${userId}/${videoId}`);
}
// export const getHistoryList = async (userId,startTime,endTime) => {
//     console.log(userId)
//     return await http.post('/user/history/list',{userId,startTime,endTime});
// }
export const getHistoryList = async (userId,param) => {
    console.log(userId)
    if(param.keyword){
        return await http.get(`/user/history/list?userId=${userId}&page=${param.page}&pageSize=${param.pageSize}&keyword=${param.keyword}`);

    }
    return await http.get(`/user/history/list?userId=${userId}&page=${param.page}&pageSize=${param.pageSize}`);
}

export const deleteHistory = async (ids) => {
    return await http.delete('/user/history/'+ids);
}
export const clearMyHistory = async () => {
    return await http.delete('/user/history/all')
}



/********** 评论 **********/
export const getCommentListByVideoID = async (videoId,userId) => {
    if(userId){
    }else {
        userId = 0
    }
    return await http.get('/user/comments/list/video?videoId='+videoId+'&userId='+userId);
}
export const getCommentListByDynamicId = async (dynamicId,userId) => {
    return await http.get(`/user/comments/list/dynamic?dynamicId=${dynamicId}&userId=${userId}`);
}

export const publishComment = async (submitForm) => {
    return await http.post('/user/comments/videoComment',submitForm);
}
export const publishDynamicComment = async (submitForm) => {
    return await http.post('/user/comments/dynamicComment',submitForm);
}
/**
 * 获取回复的评论 (不需要用户id)
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getReplyComments = async (params) => {
    return await http.get(`/user/comments/reply?page=${params.page}&pageSize=${params.pageSize}`);
}
/**
 * 获取回复我的评论
 * @param params(不需要用户id)
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAtMeComments = async (params) => {
    return await http.get(`/user/comments/at?page=${params.page}&pageSize=${params.pageSize}`);
}

/**
 * 根据id获取
 * @param params
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getCommentById = async (commentId) => {
    return await http.get(`/user/comments/${commentId}`);
}










/********** 创作中心 **********/



export const uploadVideo = async (submitForm) => {
    return await http.post('/user/video/create',submitForm)
}

/**
 * 查询自己所有的投稿视频
 * @param param
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getMyVideo = async (param) => {
    return await http.get(`/user/creation/video/list/${param.status}?page=${param.page}&pageSize=${param.pageSize}`)
}


export const deleteMyVideo = async (videoIds) => {
    return await http.delete(`/user/creation/video/${videoIds}`)
}
export const getMyComment = async (param) => {
    return await http.get(`/user/creation/comment/list/${param.type}?page=${param.page}&pageSize=${param.pageSize}`)
}

// export const deleteVideoComment = async (commentId) => {
//     return await http.delete(`/user/creation/video-comment/${commentId}`)
// }
export const deleteComment = async (commentId) => {
    return await http.delete(`/user/creation/comment/${commentId}`)
}
// export const deleteDynamicComment = async (commentId) => {
//     return await http.delete(`/user/creation/dynamic-comment/${commentId}`)
// }








/********** 动态相关 **********/
/**
 * 发布动态
 * @param submitForm
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const publishDynamic = async (submitForm) => {
    return await http.post('/user/dynamic',submitForm)
}
/**
 * 获取动态列表
 * 暂时先获取所有的，后面会改成优先获取关注的动态
 * @param
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getDynamicList = async (params) => {
    console.log(params)
    if(params.userId){
        return await http.get(`/user/dynamic/list?page=${params.page}&pageSize=${params.pageSize}&userId=${params.userId}`)
    }
    return await http.get(`/user/dynamic/list?page=${params.page}&pageSize=${params.pageSize}`)
}

/**
 * 获取用户动态列表
 * @param params
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getDynamicListByUserId = async (params) => {
    console.log(params)
    if(params.userId){
        return await http.get(`/user/dynamic/list?page=${params.page}&pageSize=${params.pageSize}&userId=${params.userId}`)
    }else{
        return await http.get(`/user/dynamic/list?page=${params.page}&pageSize=${params.pageSize}`)
    }
}

/**
 * 根据id获取
 * @param submitForm
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getDynamicById = async (dynamicId) => {
    return await http.get('/user/dynamic/'+dynamicId)
}

export const getLikeSaveStatusInDynamic = async (dynamicId) => {
    console.log(dynamicId)
    return await http.get(`/user/dynamic/action/status/${dynamicId}`)
}


export const getLikeAndforwardList = async (dynamicId) => {
    console.log(dynamicId)
    return await http.get(`/user/dynamic/likeAndforward/${dynamicId}`)
}












/********** 关注相关 **********/

export const careUP = async (form) => {
    console.log(form)
    return await http.post(`/user/concern`,form)
}

export const noCare = async (form) => {
    console.log(form)
    return await http.delete(`/user/concern/${form.fansId}/${form.upId}`)
}
export const getFollowStatus = async (upId,userId) => {
    console.log(upId)
    return await http.get(`/user/concern/status?upId=${upId}&userId=${userId}`)
}


/********** 消息相关 **********/ //14:07

// 获取聊天列表
export const getChatterList = async (page,pageSize) => {
    return await http.get(`/user/message/chat/member/list?page=${page}&pageSize=${pageSize}`)
}
export const getMsgListByUID = async (userId,page,pageSize) => {
    const res = await http.get(`/user/message/record/list/${userId}?page=${page}&pageSize=${pageSize}`)
    res.data.records.reverse()
    return res
}

/**
 * 获取未读信息
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getNoReadMsg = async () => {
    return await http.get(`/user/message/record/noRead/list`)
}

/**
 * 更新未读信息
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updateNoReadMsg = async (userId) => {
    return await http.put(`/user/message/record/noRead/${userId}`)
}



// 2025-4-6 7：47
/********** 点赞相关 **********/

export const likeVideo = async (form) => {
    return await http.post(`/user/like/video`,form)
}

export const likeComment = async (form) => {
    return await http.post(`/user/like/comment`,form)
}
export const unLikeComment = async (supporterId,likeContentId) => {
    return await http.delete(`/user/like/comment/${supporterId}/${likeContentId}`)
}

export const likeDynamic = async (form) => {
    return await http.post(`/user/like/dynamic`,form)
}

export const getLikeList = async () => {
    return await http.get(`/user/like/list`)
}

/**
 * 获取点赞用户列表
 * @param typeId
 * @param contentId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getLikeUserList = async (typeId,contentId) => {
    return await http.get('/user/like/list/user/'+typeId+'/'+contentId);
}



/********** 转发相关 **********/

export const forwardVideo = async (form) => {
    console.log(form)
    return await http.post(`/user/dynamic/forward/video`,form)
}

export const forwardDynamic = async (form) => {
    console.log(form)
    return await http.post(`/user/dynamic/forward/dynamic`,form)
}

/********** 收藏相关 **********/

/**
 * 新建收藏夹
 * @param form
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const insertSaveFolder = async (form) => {
    console.log(form)
    return await http.post(`/user/save/folder`,form)
}

/**
 * 获取收藏夹列表
 * @param id 用户id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getSaveFolder = async (id,params = {}) => {
    console.log("携带的id为："+id)
    console.log("携带的分页参数为：")
    console.log(params)
    if (params.page && params.pageSize){
        return await http.get(`/user/save/folder/list/${id}?page=${params.page}&pageSize=${params.pageSize}`)
    }
    return await http.get(`/user/save/folder/list/${id}`)
}
/**
 * 根据视频id获取收藏夹列表
 * @param id 用户id
 * @param videoId 视频id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getSaveFolderIdByVId = async (id,videoId) => {
    console.log(id)
    console.log(videoId)
    return await http.get(`/user/save/folder/${id}/${videoId}`)
}

/**
 * 收藏具体的视频
 * @param saveForm
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const saveVideo = async (saveForm) => {
    console.log(saveForm)
    return await http.post(`/user/save/record`,saveForm)
}

/**
 * 获取收藏记录列表
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const querySaveList = async (params) => {
    console.log(params)
    return await http.get(`/user/save/record/list?page=${params.page}&pageSize=${params.pageSize}&folderId=${params.folderId}&sortBy=${params.sortBy}`)
}

/**
 * 最近点赞的视频
 * @param params
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const queryLikeVideoList = async (params) => {
    console.log(params)
    return await http.get(`/user/video/like?page=${params.page}&pageSize=${params.pageSize}&userId=${params.userId}`)
}

export const getLikeSaveStatusInVideo = async (videoId) => {
    console.log(videoId)
    return await http.get(`/user/video/action/status/${videoId}`)
}




/********** 隐私相关 **********/

export const switchSaveVisible = async (val) => {
    console.log(val)
    return await http.get(`/user/privacy/save?val=${val}`)
}
export const switchLikeVisible = async (val) => {
    console.log(val)
    return await http.get(`/user/privacy/like?val=${val}`)
}
export const switchCareVisible = async (val) => {
    console.log(val)
    return await http.get(`/user/privacy/care?val=${val}`)
}
export const switchFansVisible = async (val) => {
    console.log(val)
    return await http.get(`/user/privacy/fans?val=${val}`)
}
export const switchInfoVisible = async (val) => {
    console.log(val)
    return await http.get(`/user/privacy/info?val=${val}`)
}
export const switchSchoolVisible = async (val) => {
    console.log(val)
    return await http.get(`/user/privacy/school?val=${val}`)
}
export const getPrivacy = async () => {
    return await http.get(`/user/privacy/all`)
}

export const setPrivacy = async (form) => {
    return await http.put(`/user/privacy`,form)
}

export const getSaveVisible = async (userId) => {
    return await http.get(`/user/privacy/save/${userId}`)
}

/********** 消息设置相关 **********/

export const getMessageSettings = async () => {
    return await http.get(`/user/message/settings`)
}

export const updateMessageSettings = async (form) => {
    return await http.put(`/user/message/settings`,form)
}





/********** 推荐相关 **********/

export const getHotVideos = async () => {
    return await http.get(`/user/recommend/hot-videos`)
}



/********** 弹幕相关 **********/

// export const getDanmakuList = async (videoId,fromTime,toTime) => {
//     return await http.get(`/user/danmaku?videoId=${videoId}&fromTime=${fromTime}&toTime=${toTime}`)
// }
export const getDanmakuList = async (videoId) => {
    return await http.get(`/user/danmaku/list?videoId=${videoId}`)
}